function loadJQuery(callback)
{
    try
    {
        if(typeof jQuery == "undefined" || typeof jQuery.ui == "undefined" || callback(true))
        {
            var maxLoadAttempts = 10;
            var jQueryLoadAttempts = 0;
            //We want to use jQuery as well as the UI elements, so first lets load the stylesheet by injecting it into the dom.
            var head= document.getElementsByTagName('head')[0];
            var v_css  = document.createElement('link');
            v_css.rel = 'stylesheet'
            v_css.type = 'text/css';
            v_css.href = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css';
            head.appendChild(v_css);

            //Okay, now we need the core jQuery library, lets fetch that and inject it into the dom as well
            var script= document.createElement('script');
            script.type= 'text/javascript';
            script.src= 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
            head.appendChild(script);
                    
            checkjQueryLoaded = setInterval(function()
            {             
                if(typeof jQuery != "undefined")
                {
                    //Okay, now we need the core jQuery UI library, lets fetch that and inject it into the dom as well
                    var script= document.createElement('script');
                    script.type= 'text/javascript';
                    script.src= 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js';
                    head.appendChild(script);
                    window.clearInterval(checkjQueryLoaded);
                }
                else if(maxLoadAttempts < jQueryLoadAttempts)
                {
                    window.clearInterval(checkjQueryLoaded);
                }
                jQueryLoadAttempts++;
            },300);
            
            jQueryLoadAttempts = 0;        
        
            checkLoaded = setInterval(function()
            {             
                if(typeof jQuery != "undefined" && typeof jQuery.ui != "undefined")
                {
                    window.clearInterval(checkLoaded);
                    callback(true);
                }
                else if(maxLoadAttempts < jQueryLoadAttempts)
                {
                    window.clearInterval(checkLoaded);
                    callback(false);
                }
                jQueryLoadAttempts++;
            },500);
        }
    }
    catch(exception)
    {
        callback(false);
    }
}
loadJQuery(function(loadSuccess){
    if(loadSuccess)
    {
		var mls,price,address,metro,url;
		url=window.location;
		if(/www.redfin.com/.test(window.location)){
			mls=$("td#mls_id").html().trim();
			price=$("div.price").text().match(/\$\d+,\d+/);
			address=$("span#address_line_1").text().trim()+'%20'+$("span#address_line_2").text().trim();
			$("table#property_basic_details%20td").each(function(i,td){
				if($(td).text().match(/Community:/)){
					metro=$(td).next("td").text().trim();
					return false;
				}
			});
		}
		else if(/mrislistings.mris.com/.test(window.location)){
			mls=$($(".d42766m18")[0]).html().trim();
			price=$($("td.d42766m30 span.d42766m18")[1]).html().trim();
			address=$(".d42766m20").html().trim();
			$("td.d42766m27 span.d42766m11").each(function(i,span){
				if($(span).text().match(/Legal Sub:/)){
					metro=$(span).next("span").text().trim();
					return false;
				}
			});
		}
		if(!mls)mls="";
		if(!price)price="";
		if(!address)address="";
		if(!metro)metro="";
        $(document.getElementsByTagName('body')[0]).append('<div id=infoNotice title="Success"><div><div><h1>House Hunting</h1><p></p><hr style="display:none;"><div>* Required</div></div><div><form action="https://docs.google.com/spreadsheet/formResponse?formkey=dG5SbEhhMmxjdUpVRFBUTlNBa0hsZFE6MQ&amp;ifq" method="POST" id="ss-form"><br><div><div><div><label for="entry_0">MLS #<span>*</span></label><label for="entry_0"></label><input type="text" name="entry.0.single" value="'+mls+'" id="entry_0"></div></div></div><br> <div><div><div><label for="entry_6">Price<span>*</span></label><label for="entry_6"></label><input type="text" name="entry.6.single" value="'+price+'" id="entry_6"></div></div></div><br> <div><div><div><label for="entry_3">Address<span>*</span></label><label for="entry_3"></label><input type="text" name="entry.3.single" value="'+address+'" id="entry_3"></div></div></div><br> <div><div><div><label for="entry_1">metro stop / Neighborhood</label><label for="entry_1"></label><input type="text" name="entry.1.single" value="'+metro+'" id="entry_1"></div></div></div><br> <div><div><div style="display:none"><label for="entry_2">url</label><label for="entry_2"></label><input type="text" name="entry.2.single" value="'+url+'" id="entry_2"></div></div></div><br> <div><div><div><label for="entry_5">Comments</label><label for="entry_5"></label><textarea name="entry.5.single" rows="8" cols="75" id="entry_5"></textarea></div></div></div><br><input type="hidden" name="pageNumber" value="0"><input type="hidden" name="backupCache" value=""><div><div><input type="submit" name="submit" value="Submit"></div></div></form></div></div></div>'); 
        $( "#infoNotice" ).dialog({ modal: true});  
    }
    else
    {
        alert('Couldn\'t load jQuery :( ');    
    }
});